# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : HTTP非流式请求示例.py
# @Author: dongguangwen
# @Date  : 2025-03-22 11:21
import requests

url = "https://spark-api-open.xf-yun.com/v1/chat/completions"
data = {
    "model": "generalv3.5",  # 指定请求的模型
    "messages": [
        {
            "role": "user",
            "content": "你是谁"
        }
    ],
    "tools": [
        {
            "type": "function",
            "function": {
                "name": "get_current_weather",
                "description": "返回实时天气",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "location": {
                            "type": "string",
                            "description": "河北省承德市双桥区",
                        },
                        "format": {
                            "type": "string",
                            "enum": ["celsius", "fahrenheit"],
                            "description": "使用本地区常用的温度单位计量",
                        },
                    },
                    "required": ["location", "format"],
                }
            }
        }
    ]
}
header = {
    "Authorization": "Bearer 123456"  # 注意此处把“123456”替换为自己的APIPassword
}
response = requests.post(url, headers=header, json=data)
print(response.text)

"""
{"code":0,"message":"Success","sid":"cha000b07fd@dx195bbe0bcd19a4b532","choices":[{"message":{"role":"assistant","content":"您好，我是科大讯飞研发的认知智能大模型，我的名字叫讯飞星火认知大模型。我可以和人类进行自然交流，解答问题，高效完成各领域认知智能需求。"},"index":0}],"usage":{"prompt_tokens":2,"completion_tokens":40,"total_tokens":42}}
"""
